home *** CD-ROM | disk | FTP | other *** search
- Path: cnn.iper.net!usenet
- From: giampo@imar.net (gianluca porcarelli)
- Newsgroups: comp.lang.c++
- Subject: Re: ******** Questions about MSVC++ programming ********
- Date: Wed, 10 Jan 1996 13:31:57 GMT
- Organization: IPER-NET Internet Services +39-541-378202
- Message-ID: <4d0ge7$8k8@cnn.iper.net>
- References: <4cbm3n$1r4i@mercury.cc.uottawa.ca>
- NNTP-Posting-Host: giampo.imar.net
- X-Newsreader: Forte Free Agent 1.0.82
-
- jxie@csi.uottawa.ca (Jun Xie) wrote:
-
- >Hi,
-
- >I am new to the MSVC++ Ver 1.5 and MFC and have following questions.
- >I appreciate it very much if you could answer any one of them or
- >tell me the place (book, webpage, online help etc) where I can find
- >the answers.
- >............
- >4) How to get the current width and height of the client device context?
- > I hope my graphics images drawn on the DC are proportional to its size.
- > That means if you change the size of the window, the graphics image will
- > change accordingly. I tried to use GetDeviceCaps() as follows, but the
- > width and heigth returned are always 1024 and 768 respectively.
-
- > void CXXXView::OnXXX()
- > {
- > // TODO: Add your command handler code here
- > CClientDC dc(this);
- > int width, height;
-
- > width = dc.GetDeviceCaps(HORZRES);
- > height = dc.GetDeviceCaps(VERTRES);
- > .
- > .
- > .
- > }
-
- >Thank you for your attention.
-
- Try to use "GetClientRect(clientRect)" in your function clientRect
- return the size of the client area.
- This example try to draw a bitmap in the client area.
-
- void CPrimaView::OnDraw(CDC* pDC)
- {
- CRect clientRect;
- CSize Ampiezza(640, 396);
- CSize AmpiezzaSchermo;
- GetClientRect(clientRect); // device coords
- BOOL vero;
- double appXY, appYX, appX, appY;
-
- // Ampiezza = m_bmSize;
- appX = Ampiezza.cx;
- appY = Ampiezza.cy;
- AmpiezzaSchermo.cx = clientRect.Width();
- AmpiezzaSchermo.cy = clientRect.Height();
- appXY = (double)(appX / appY);
- appYX = (double)(appY / appX);
-
- if (Ampiezza.cx > Ampiezza.cy) {
- AmpiezzaSchermo.cx = (int)(AmpiezzaSchermo.cy * appXY);
- if (AmpiezzaSchermo.cx > clientRect.Width()) {
- AmpiezzaSchermo.cx = clientRect.Width();
- AmpiezzaSchermo.cy = (int)(AmpiezzaSchermo.cx * appYX);
- }
- }
- else {
- AmpiezzaSchermo.cy = (int)(AmpiezzaSchermo.cx * appYX);
- if (AmpiezzaSchermo.cy > clientRect.Height()) {
- AmpiezzaSchermo.cy = clientRect.Height();
- AmpiezzaSchermo.cx = (int)(AmpiezzaSchermo.cy *
- appXY);
- }
- }
-
- pDC->SetMapMode(MM_TEXT);
- pDC->DPtoLP(&Ampiezza);
- pDC->DPtoLP(&AmpiezzaSchermo); // logical
- vero = pDC->StretchBlt(0, 0, AmpiezzaSchermo.cx,
- AmpiezzaSchermo.cy, // disegna solamente una figura della
- m_pDisplayMemDC, 0, 0, Ampiezza.cx, Ampiezza.cy,
- SRCCOPY); // grandezza della figura caricata cioΦ
-
- }
-
- ==============================================
- Gianluca Porcarelli
-
- Chiaravalle (ANCONA)
- (ITALY)
- email: giampo@imar.net
- =============================================
-
-